        TITL DAI FIRMWARE 0EA40-0EBC0  V1.1
        ORG   :EA40
*
*
*
****************************
* part of RUN TALK (0E67B) *
****************************
*
* Sets oscillator volumes.
*
* Entry: A:  New volume.
*        HL: Address POROM/POR1M.
*
MPT48   MOV   M,A       Update POR0M/POR1M
        LXI   D,:FA70
        DAD   D         HL= POR0/POR1
        MOV   M,A       Update osc.volume
        POP   H         Get parameter pntr
RTK55   INX   H         Pnts to next code
        JMP   RTK10     Handle next code
*
        DATA  :FF
        DATA  :FF
        DATA  :FF
        DATA  :FF
        DATA  :FF
*
*************************
* RUN basicfunction ABS *
*************************
*
RABS    RST   4         MFABS
        DATA  :18
        RET 
*
**************************
* RUN basicfunction ALOG *
**************************
*
RALOG   RST   4         MALOG
        DATA  :30
        RET 
*
*************************
* RUN basicfunction EXP *
*************************
*
REXP    RST   4         MEXP
        DATA  :2A
        RET 
*
**************************
* RUN basicfunction FRAC *
**************************
*
RFRAC   RST   4         MFRAC
        DATA  :21
        RET 
*
*************************
* RUN basicfunction LOG *
*************************
*
RLOG    RST   4         MLOG
        DATA  :27
        RET 
*
**************************
* RUN basicfunction LOGT *
**************************
*
RLOGT   RST   4         MLOGT
        DATA  :2D
        RET 
*
*************************
* RUN basicfunction SQR *
*************************
*
RSQR    RST   4         MSQR
        DATA  :33
        RET 
*
*************************
* RUN basicfunction SIN *
*************************
*
RSIN    RST   4         MSIN
        DATA  :36
        RET 
*
*************************
* RUN basicfunction COS *
*************************
*
RCOS    RST   4         MCOS
        DATA  :39
        RET 
*
*************************
* RUN basicfunction TAN *
*************************
*
RTAN    RST   4         MTAN
        DATA  :3C
        RET 
*
**************************
* RUN basicfunction ASIN *
**************************
*
RASIN   RST   4         MASIN
        DATA  :3F
        RET 
*
**************************
* RUN basicfunction ACOS *
**************************
*
RACOS   RST   4         MACOS
        DATA  :42
        RET 
*
*
**************************
* RUN basicfunction ATAN *
**************************
*
RATN    RST   4         MATAN
        DATA  :45
        RET 
*
**************************
* RUN basicfunction STR$ *
**************************
*
* Converts a FPT number into a string.
*
RSTR    CALL  FBCP      Convert MACC for FPT output
 REM string in DECBUF
        NOP 
        NOP 
        NOP 
RST20   LHLD  DOBUF     Get addr DECBUF
        MVI   E,:01     Pretend it is a variable
        RET 
*
**************************
* RUN basicfunction HEX$ *
**************************
*
* Converts a INT number into an equivalent string.
*
RHEX    CALL  REXNA     Eval expr, result in MACC
        CALL  XHBC      Conv. MACC to HEX for output
        JMP   RST20     Get addr DECBUF, pretend it
 REM is a variable
*
*************************
* RUN basicfunction SPC *
*************************
*
* Returns a string of a number of spaces.
* From SPC10 used by TAB if DOUTC<>0.
*
RSPC    CALL  REXI1     Get nr of spaces in A
 REM
* Entry from RTAB:
 REM
SPC10   CALL  SHREQ     Get place in heap for string
 REM of spaces
        PUSH  H         Save pntr to heap
SPC20   ORA   A
        JZ    SPC30     Jump if ready
        INX   H
        MVI   M,:20     Space into heap
        DCR   A
        JMP   SPC20     Next space
SPC30   POP   H         HL pnts to start string
        JMP   RCR10     Pretend it is a temp string
*
*************************
* RUN basicfunction TAB *
*************************
*
* Returns a string of spaces to move cursor to a
* given character position (only to the right).
* Works only if output switch DOUTC=0, else it
* returns one space only.
*
RTAB    CALL  MPT50     Get nr of tabs in L,
 REM DOUTC in A
*
***********
* RUN TAB *
***********
*
* The old routine worked only for DOUTC=0. Now
* DOUTC is not checked anymore, but the Z-flag
* set by CE60 is evaluated. If Z=1 (all O.K.),
* the TAB-instruction is executed. If Z=0, then
* the number of tab's is not correct. Then only
* one space is printed.
*
        RAR             ] Dummy to preserve Z-flag
        MVI   A,:01     Init 1 space
        JNZ   SPC10     Jump if DOUTC<>0
        MOV   A,L       Get nr of tabs
        NOP 
        NOP 
        RST   5         Ask cursor pos and size
        DATA  :0C       char screen
        SUB   L         Calc nr of spaces reqd
        JNC   SPC10     Run SPC if not past tab pos
        XRA   A         If past TAB:
        JMP   SPC10     Run SPC for no spaces
*
**************************
* RUN basicfunction CURX *
**************************
*
RCURX   RST   5         Ask cursor pos and size
        DATA  :0C       char screen
        MOV   A,L       X-coord in A
        JMP   FR1BY     and into MACC
*
**************************
* RUN basicfunction CURY *
**************************
*
RCURY   RST   5         Ask cursor pos and size
        DATA  :0C       char screen
        MOV   A,H       Y-coord in A
        JMP   FR1BY     and in MACC
*
*************************
* RUN basicfunction LEN *
*************************
*
* Given a string, returns length of the string.
*
RLEN    CALL  REXSR     Eval string expr
RLE10   MOV   A,M       Get length in A
        JMP   FR1BY     and into MACC
*
*************************
* RUN basicfunction ASC *
*************************
*
* Given a string, returns ASCII value of 1st char.
*
RASC    CALL  REXSR     Eval string expr
        MOV   A,M       Get length in A
        JMP   MPT51     Check if length is 0; get
 REM 1st char in MACC if not
*
**************************
* RUN basicfunction CHR$ *
**************************
*
RCHR    CALL  REXI1     Get argument value in A
        PUSH  PSW       Save it
        MVI   A,:01
        CALL  SHREQ     Find place in heap for
 REM a 1-byte string
        POP   PSW       Get argument
        INX   H
        MOV   M,A       Store it in Heap
        DCX   H         Pnts to length byte
 REM
* Entry from 'SPC':
 REM
RCR10   MVI   E,:02     Status: temporary
        RET 
*
***************************
* RUN basicfunction LEFT$ *
***************************
*
* Given a string, returns a number of characters
* from the left end.
*
RLEFT   CALL  REXPS     Eval string expr
        PUSH  H         Save string pntr
        PUSH  D
        CALL  REXIK     Reqd length in A
        MVI   D,:00
RLF10   MOV   E,A       Length in DE
RLF20   CALL  SHMID     Extract substring
        JNC   ERRRA     Evt. run error 'NUMBER OUT
 REM OF RANGE'
        POP   D
        XTHL
        MOV   A,E       Get status
        CPI   :02       Temporary?
        CZ    SHREL     Then clear heap entry
        POP   H
        MVI   E,:02     Status temporary
        RET 
*
****************************
* RUN basicfunction RIGHT$ *
****************************
*
* Extracts a number of characters from the
* right end of a given string.
*
RRIGHT  CALL  REXPS     Eval string expr
        PUSH  H         Save string pntr
        PUSH  D
        CALL  REXIK     Get length substring
        MOV   E,A       in E
        MOV   A,M       Get total string length
        SUB   E
        MOV   D,A       Startposition in D
        JMP   RLF20     Extract substring
*
**************************
* RUN basicfunction MID$ *
**************************
*
RMID    CALL  REXPS     Eval string expr
        PUSH  H         Save string pntr
        PUSH  D
        CALL  REXIK     Get startposition
        MOV   D,A       in D
        CALL  REXI1     Get length in A
        JMP   RLF10     Extract substring
*
******************************
* GET VALUE OF ARGUMENT IN A *
******************************
*
* Exit: DEHL preserved.
*
REXIK   PUSH  H
        PUSH  D
        CALL  REXI1     Get value of argument in A
        POP   D
        POP   H
        RET 
*
*************************
* RUN basicfunction VAL *
*************************
*
* Takes a string and converts it to a FPT number.
*
RVAL    CALL  REXSR     Eval string expr
        PUSH  B
SUEPT   MOV   A,M       Length of string in A
        STA   EFMOD     and in EFECT
        INX   H         HL pnts to 1st string byte
        SHLD  EFEPT     Addr into EFEPT
        MVI   C,:00     Char count
        LXI   H,EFSW
        MVI   M,:01     Input from string
        CALL  XFCB      encode FPT number into MACC
        DCR   M         Input from keyboard
        MVI   A,:0A     If over/underflow: run
        JNC   ERROR     error 'INVALID NUMBER'
        POP   B
        RET 
*
*************************
* RUN basicfunction FRE *
*************************
*
* Returns a INT given size of free RAM space.
* Result in MACC.
* FR2BY: Also used to copy HL into MACC.
*
* Exit: BC preserved, AFDEHL corrupted.
*
RFRE    CALL  SIZE      Calc free RAM space in HL
FR2BY   XRA   A
        PUSH  B
        PUSH  D
        MOV   C,H       ) Free space in CD
        MOV   D,L       )
        MOV   B,A       A,B=0
        RST   4         Copy reg A,B,C,D into MACC
        DATA  :12
        POP   D
        POP   B
        RET 
*
****************************
* CALCULATE FREE RAM SPACE *
****************************
*
* Exit: HL: Free RAM space.
*       DE: STBUSE.
*       ABC preserved, F corrupted.
*
SIZE    LHLD  STBUSE    Get end symtab
        XCHG            in DE
        LHLD  SCRBOT    Get bottom screen RAM
        CALL  SUBDE     Calc. free space in HL
        RET 
*
**************************
* RUN basicfunction FREQ *
**************************
*
* Given a frequency in Hz, returns a period in
* 'oscillator cycles' (INT).
*
* Entry: MACC: Value for freq.
* Exit:  BC preserved, AFDEHL corrupted.
*
RFREQ   LXI   H,WORKE   Startaddr scratch area for
 REM expression evaluation
        RST   4         Copy reqd freq to scratch
        DATA  :0F       area
        PUSH  H         Save startaddr scratch area
        LXI   H,FPOSC   Addr sound constant
        RST   4         Sound constant into MACC
        DATA  :0C
        POP   H         Get start scratch area
        RST   4         Calc sound const/reqd freq
        DATA  :09
        RST   4         Change it to INT
        DATA  :48
        PUSH  B
        RST   4         Copy result to reg A,B,C,D
        DATA  :15
        ORA   B         > 64K ? Then run error
        JNZ   ERRRA     'NUMBER OUT OF RANGE'
        POP   B
        RET 
*
************
* RUN GETC *
************
*
* Better entry to keyboard scan routine to
* avoid keybounce.
*
        XRA   A         ]
        STA   KNSCAN    ] Clear breakflag
        CALL  GETC      ] Run GETC
FR1BY   MOV   L,A       Result in L
        MVI   H,:00
        JMP   FR2BY     Result into MACC
*
*************************
* RUN basicfunction INP *
*************************
*
* Reads a byte from a Real World address (DCE-bus).
*
RINP    CALL  REXI1     Get RW addr in A
        MOV   D,A       and in D
        CALL  RWIP      Get input from DCE-bus
        MOV   A,E       Result in A
        JMP   FR1BY     Result into MACC
*
*************************
* RUN basicfunction INT *
*************************
*
* Returns a integer FPT value, just less than the
* FPT argument given.
* REMARK: Routine is wrong if -1 < nr < 0. Then
*         the result is -1 !
*
RINT    PUSH  B
        RST   4         Copy MACC to reg A,B,C,D
        DATA  :15
*
***********
* RUN INT *
***********
*
* Running INT on a number with value 0 gave as
* result: -1. Now this failure is corrected.
*
        LXI   H,WORKE   ]
        RST   4         ] Copy MACC to WORKE
        DATA  :0F       ]
        POP   B         ]
        RST   4         ] MACC = INT (MACC)
        DATA  :1E       ] for FPT number
        ORA   A         ] Set flags on exp byte
        RP              ] Ready if nr positive
        JMP   :CEC5     ]
*
*********************
* DATA - (not used) *
*********************
*
L0E240  DATA  :81       FPT (-1)
        DATA  :80
        DATA  :00
        DATA  :00
*
****************************
* RUN basicfunction VARPTR *
****************************
*
RVPT    CALL  RVAR      Get varptr in HL, T/L in A
        JMP   FR2BY     Varptr into MACC
*
**************************
* RUN basicfunction XMAX *
**************************
*
RXMAX   CALL  L0E245    Get max Y,X-coord graph area
        XCHG            Max X-coord in HL
        JMP   FR2BY     and into MACC
*
**************************
* RUN basicfunction YMAX *
**************************
*
RYMAX   CALL  L0E245    Get max Y,X-coord graph area
        JMP   FR1BY     Max Y-coord into MACC
*
******************************************
* GET MAX. Y,X-COORDINATES GRAPHICS AREA *
******************************************
*
* Exit: DE: Max. X-coordinate.
*       A:  Max. Y-coordinate.
*       BC preserved.
*
L0E245  LXI   H,:0000   ) Coord dot 0,0
        PUSH  B         )
        MOV   C,H       )
        RST   5         Ask colour of point and
        DATA  :27       size graphics screen
        JC    SCRER     Evt run screen error
        MOV   A,B       Max Y-coord in A
        POP   B
        RET 
*
*
*
        UNL
RTK10   EQU   :CD67
FBCP    EQU   :CE9B
DOBUF   EQU   :C033
REXNA   EQU   :E808
XHBC    EQU   :C02D
REXI1   EQU   :E71D
SHREQ   EQU   :D18B
MPT50   EQU   :CE60
REXSR   EQU   :E791
MPT51   EQU   :CF7E
REXPS   EQU   :E79D
SHMID   EQU   :D14F
ERRRA   EQU   :DA15
SHREL   EQU   :D187
EFMOD   EQU   :0134
EFEPT   EQU   :0132
EFSW    EQU   :0135
XFCB    EQU   :C01E
ERROR   EQU   :D9F5
STBUSE  EQU   :02A3
SCRBOT  EQU   :02A5
SUBDE   EQU   :DE1A
WORKE   EQU   :0129
FPOSC   EQU   :D0ED
KNSCAN  EQU   :02B9
GETC    EQU   :D6BE
RWIP    EQU   :D8E0
RVAR    EQU   :E963
SCRER   EQU   :E602
        LST
        END 
